﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Microsoft.Office.OneNote
{
    internal static class Contract
    {
        public static void RequiresNotNull(object obj, string parameter)
        {
            if (ReferenceEquals(null, obj))
            {
                throw new ArgumentNullException(parameter);
            }
        }

        public static void RequiresNotNullNorEmpty(string str, string parameter)
        {
            RequiresNotNull(str, parameter);

            if (str.Length == 0)
            {
                string message = FormatUI(ErrorMessages.ArgumentEmptyString, parameter);
                throw new ArgumentException(message, parameter);
            }
        }

        public static void RequiresNotNullAndValid(OneNoteObject obj, string parameter)
        {
            Contract.RequiresNotNull(obj, parameter);
            obj.CheckValid();
        }

        public static void RequiresValidFileName(string str, string parameter)
        {
            RequiresNotNullNorEmpty(str, parameter);

            if (PathHelper.ContainsInvalidFileNameChars(str))
            {
                throw new ArgumentException(FormatUI(ErrorMessages.InvalidFileName, str), parameter);
            }
        }



        private static string FormatUI(string format, params object[] args)
        {
            return string.Format(CultureInfo.CurrentUICulture, format, args);
        }
    }
}
